var ws, hid, did, dname, djob, offices;
document.addEventListener('plusready', function(){
	ws = plus.webview.currentWebview();
	hid = ws.hid;	//医院id
	did = ws.did;	//医生id
	dname = ws.dname;	//医生名
	djob = ws.djob;	//医生级别
	offices = ws.offices;	//就诊科室
	console.log(hid);
	showWating(); 
	console.log(apiRoot+"/home/bespoke/appointTime/hid/"+hid);
	$.ajax({
		type:"get",
		url:apiRoot+"/home/bespoke/appointTime",
		data:{hid :hid},
		dataType :'json',
		success :function(data){
//			console.log(JSON.stringify(data));
			plus.nativeUI.closeWaiting();
			if(data.length > 0){
				var list = '';
				$.each(data, function(k, v) {
					list += '<li class="mui-table-view-cell ' + (v.isRe == '0' ? '' : 'show') + '" aid="'+v.aid+'">'+
			                '<a class="mui-navigate-right">'+
			                    '<span><span class="wen">' + v.date + ' ';
	                    switch(v.week){
	                    	case '0':list += '周日';break;
	                    	case '1':list += '周一';break;
	                    	case '2':list += '周二';break;
	                    	case '3':list += '周三';break;
	                    	case '4':list += '周四';break;
	                    	case '5':list += '周五';break;
	                    	case '6':list += '周六';break;
	                    }
			            list += (v.hours == '1' ? ' 上午' :' 下午') + '</span>  ' + (v.isRe == '0' ? '已满' : '可约') + '</span>'+
			                '</a>'+
			            '</li>';
				});
				$('.bespoke').html(list);
				$('.show').on('tap', function() {
					var _this = $(this);
					var aid = _this.attr('aid');
					var text1 = _this.find('.wen').text();
					$('#cont').text(text1+'');
					var str = ''; 
					$.each(data, function(k, v) {
						if(v.aid == aid){
							$.each(v.times, function(k1, v1) {
//								console.log(JSON.stringify(v1));
								str += '<li class="mui-table-view-cell" onclick="sure(\''+ v1.aid +'\',\''+ text1 +'\',\''+ v1.timeslot +'\')">'+
					  	            '<span>'+v1.timeslot+'</span><span class="mui-pull-right">剩余'+v1.mark+'号</span>'+
					  	        '</li>';
							});
						}
					});
					$('.list').html(str);
					$('.time-zzao').show();
					$('.time-tc').show();
				});
			}
		},
		error :function(e){
			console.log(JSON.stringify(e));
			errortoast();
		}
	});
}, false)
//点击选择好的时间跳入	——>aid：时间段id
function sure(aid, time, tlog){
	var str = time+" "+tlog; 
	goNewPage('yuyuegh-queren.html',{aid:aid, str:str, hid:hid, did:did, dname:dname, djob:djob, offices:offices, spage:ws.id});
}
